package com.lxy.controller;

import com.lxy.config.MinioProperties;
import com.lxy.service.MinioService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamSource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@Api(tags = "minio管理")
@RequestMapping("/minio")
public class UploadController {

    @Autowired
    MinioProperties minioProperties;

    @Autowired
    MinioService minioService;

    @ApiOperation("文件上传")
    @PostMapping("/upload")
    public String upload(MultipartFile file){
        String url = minioService.upload(minioProperties.getBucketName(),file);
        return url;
    }

    @ApiOperation("文件下载")
    @GetMapping("/download")
    public ResponseEntity<InputStreamSource> download(String url){
        ResponseEntity<InputStreamSource> download = minioService.download(url);
        return download;
    }

}
